<?php
class IndexModel extends Model{
	//获取当前用户导航(权限)
	/**
	 * 
	 * @param string $admin_name 用户名
	 * @return Ambigous <$list, multitype:multitype: >
	 */
	public function getNav($admin_name,$password){
		//view_userprivilege为数据库中的视图
		$sql="select * from view_userprivilege where name='{$admin_name}' and pwd='{$password}'";
		return $this->db->getRow($sql);
	}
	
	//获取热门图书
	/**
	 * @return array 二维数组
	 */
	public function getHotBook(){
		$sql="SELECT * FROM ( SELECT bookid, COUNT(bookid) AS popular 
				FROM tb_borrow GROUP BY bookid ) AS borrow 
				JOIN ( SELECT tb_bookinfo.*, tb_bookcase.name, tb_publishing.pubname, tb_booktype.typename 
				FROM tb_bookinfo 
				LEFT JOIN tb_bookcase ON tb_bookinfo.bookcase = tb_bookcase.id 
				JOIN tb_publishing ON tb_bookinfo.ISBN = tb_publishing.ISBN 
				JOIN tb_booktype ON tb_bookinfo.typeid = tb_booktype.id 
				WHERE tb_bookinfo.del = 0 ) AS book ON borrow.bookid = book.id 
				ORDER BY borrow.popular DESC LIMIT 10";
		return $this->db->getAll($sql);
	}
}
